﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace UFIDA.U9.Cust.XH.PlugBE.Model
{
    /// <summary>
    /// 请款
    /// (付款申请)物料类
    /// </summary>
    public class PayReqModel
    {
        public PayReqModel(UFIDA.U9.AP.Payment.PayReqFundHead m)
        {
            this.DocumentType_Name = m.DocumentType?.Name;
            this.DocNo = m.DocNo;
            this.PayRFDate = m.PayRFDate;
            this.ExpectPayDate = m.ExpectPayDate;
            this.CreatedBy = m.CreatedBy;
            this.CreatedOn = m.CreatedOn;

            this.RequestObjType = UFIDA.U9.CBO.FI.Enums.RecPayObjectTypeEnum.EnumRes.GetResource(m.RequestObjType.Name);
            foreach (UFIDA.U9.AP.Payment.PayReqFundUse item in m.PayReqFundUses)
            {
                this.FundUse_Name = UFIDA.U9.AP.Enums.RequestFundUseEnum.EnumRes.GetResource(item.ReqFundUse.Name);
            }
            this.Currency_Name = m.ReqFundPC.Name;
            this.Memo = m.Memo;
            this.SrcOrg_Name = m.SrcBizOwnerOrg.Name;
            this.SettleOrg_Name = m.SettleOrg.Name;
            this.BizOrg_Name = m.BizOrg.Name;
            this.Transactor_Name = m.Transactor.Name;
            this.Status = UFIDA.U9.CBO.FI.Enums.InDirectHandleBillDocStatusEnum.EnumRes.GetResource(m.DocStatus.Name);
        }
        public string DocumentType_Name { get; set; }
        public string DocNo { get; set; }
        public DateTime PayRFDate { get; set; }
        public DateTime ExpectPayDate { get; set; }
        public string CreatedBy { get; set; }
        public DateTime CreatedOn { get; set; }
        public string RequestObjType { get; set; }
        public string FundUse_Name { get; set; }
        public string Currency_Name { get; set; }
        public string SrcOrg_Name { get; set; }
        public string SettleOrg_Name { get; set; }
        public string BizOrg_Name { get; set; }
        public string Transactor_Name { get; set; }
        public string Status { get; set; }
        public string Memo { get; set; }
    }


    public class PayReqLineModel
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="m"></param>
        /// <param name="headUsed">主表用途</param>
        public PayReqLineModel(UFIDA.U9.AP.Payment.PayReqFundDetail m, string headUsed)
        {
            this.PrePayType = UFIDA.U9.CBO.FI.Enums.PrePayObjEnum.EnumRes.GetResource(m.PrePayType.Name);
            this.SrcBillType = UFIDA.U9.AP.Enums.PayReqFundSrcDocTypeEnum.EnumRes.GetResource(m.SrcBillType.Name);
            this.SrcBillNum = m.SrcBillNum;
            this.ItemCode = m.Item.ItemCode;
            this.ItemName = m.Item.ItemName;
            this.PUAmount = m.PUAmount;
            this.PUUOM_Name = m.PUom.Name;
            this.Price = m.Price;
            this.RFMoney = m.RFMoney.TotalMoney;
            this.SuppName = m.PayReqFundUse.SuppName;
            this.SttlMethod = m.PayReqFundUse.SttlMethod.Name;
            this.OppAccBk = m.PayReqFundUse.OppAccBk;
            this.OppAccBkAccount = m.PayReqFundUse.OppAccBkAccount;
            this.RecBkAccName = m.PayReqFundUse.RecBkAccName;
            if (headUsed == "标准")
            {
                UFIDA.U9.AP.APBill.APBillHead rpm = UFIDA.U9.AP.APBill.APBillHead.Finder.FindByID(m.SrcBillID);
                if (rpm != null)
                {
                    //查找应付单发票
                    this.InvoiceNo = rpm.InvoiceNum;
                    this.InvoiceDate = rpm.InvoiceDate;
                }
                
            }
        }
        public string PrePayType { get; set; }
        public string SrcBillType { get; set; }
        public string SrcBillNum { get; set; }
        public string ItemCode { get; set; }
        public string ItemName { get; set; }
        public decimal PUAmount { get; set; }
        public decimal Price { get; set; }
        public string PUUOM_Name { get; set; }
        public decimal RFMoney { get; set; }

        public string SuppName { get; set; }
        public string SttlMethod { get; set; }
        public string OppAccBk { get; set; }
        public string OppAccBkAccount { get; set; }
        public string RecBkAccName { get; set; }
        public string InvoiceNo { get; set; }
        public DateTime InvoiceDate { get; set; }



    }
}
